<?
//引入所有子系统信息
include_once("../../../common/script/extender_import.php");


//**获取当前板块资料，必然载入，后续很多读取板块数据库的表格，都写成动态的了。
$_plate=$plate['member'];


//获取板块的设置
include_once("../model/setting.php");


//根据页面数量信息，筛选信息，创造url，供页码,跳转等使用
include_once("script/set_url.php");
?>

<?


//传递了什么数据过来

print_r2($_REQUEST);



//01获取当前套餐的资料，用于下单
$now_product_set=select_one_line_all_items($table_prefix."product_data","nid = '{$_REQUEST['ai_product']}'");
//print_r2($now_product_set);


//02获取套餐的日程
$now_product_set_schedule=select_lines_all_items($table_prefix."product_schedule","","product_nid = '{$_REQUEST['ai_product']}'","");




//查出所有贫困生

//循环所有要下单的学生
$_student_nid_list_str=implode( "','",$_REQUEST['nid']);
//echo $_student_nid_list_str;

$student_list=select_lines_all_items($table_prefix."member_child","nid desc","nid in ('{$_student_nid_list_str}')","");
//print_r2($student_list);

$_mark="mm".date("YmdHis");
foreach ($student_list as $k=>$v)
{
    //根据套餐和child信息制单
    $_order['ai_order_name']   = $now_product_set['title'];
    $_order['ai_student_info'] = $v['school'] . " " . $v['grade'] . " " . $v['class_'];
    $_order['ai_order_price']  = "0.00";
    $_order['ai_user_id']      = "0";
    $_order['ai_pay_status']   = "1";
    $_order['ai_student_nid']  = $v['nid'];
    $_order['ai_order_sn']     = $_mark;
    $_order['ai_student_name'] = $v['name'];
    $_order['ai_order_status'] = 0;
    $_order['ai_remark']       = "后台下单";
    $_order['ai_product_id']   = $now_product_set['nid'];
    $_order['ai_startdate']    = "2025-06-09 00:00:00";
    $_order['ai_enddate']      = "2025-07-11 00:00:00";
    $_order['ai_student_school']      = $v['school'];
    $_order['ai_student_grade']      = $v['grade'];
    $_order['ai_student_class']      = $v['class_'];


    $_sql=insert_date($table_prefix."order_info",$_order);
    //echo "<br/>";
    $query = do_query($_sql) or die (mysqli_error().$_sql);
}




//获取上面的订单，循环插入订单detail

$_now_order_list=select_lines_all_items($table_prefix."order_info","","order_sn = '{$_mark}'","");


//print_r2($_now_order_list);


foreach ($_now_order_list as $k=>$order)
{

    //补充产品日程 detail
    foreach ($now_product_set_schedule as $k=>$v)
    {

        //
        $_order_detail['ai_order_nid'] = $order['order_id'];
        $_order_detail['ai_ondate'] = $v['apply_date'];
        $_order_detail['ai_product_nid'] = $order['product_id'];
        $_order_detail['ai_student_nid'] = $order['student_nid'];
        $_order_detail['ai_user_nid'] = $order['user_id'];
        $_order_detail['ai_name'] = $order['student_name'];
        $_order_detail['ai_price'] = "0.0";
        $_order_detail['ai_number'] = "1";
        $_order_detail['ai_product_name'] = $v['milk_name'];
        $_order_detail['ai_order_name'] = $order['order_name'];
        $_order_detail['ai_add_date'] = date("Y-m-d H:i:s"); // 当前日期和时间
        $_order_detail['ai_school'] = $order['student_school'];
        $_order_detail['ai_grade']  = $order['student_grade'];
        $_order_detail['ai_class_'] = $order['student_class'];
        $_order_detail['ai_status'] = "正常";

        echo $sql=insert_data($table_prefix."order_detail",$_order_detail);
        echo "<br/>";
        do_query($sql);

    }

}




//最后更新一下这个订单的状态，为已经补单
$update_sql=update_date($table_prefix."order_info",array("ai_fix_order_detail"=>"补单完成"),"order_id",$order['order_id']);
//echo "<br/>";
do_query($update_sql);

?>

